const { regClass } = Laya;
import { ItemImgBase } from "./ItemImg.generated";

@regClass()
export class ItemImg extends ItemImgBase {
    public setInfo(info: string) {
        this.TxtInfo.text = info;
    }
    public setTexture(texture: Laya.Texture) {
        this.Img.source = texture;
        // 大小自适应
        const bz = this.ImgBg.width / this.ImgBg.height;
        let sc = 1;
        if (this.Img.source.sourceWidth / this.Img.source.sourceHeight > bz) {
            sc = this.ImgBg.height / this.Img.source.sourceHeight
        } else {
            sc = this.ImgBg.width / this.Img.source.sourceWidth
        }
        this.Img.scale(sc, sc);
        this.TxtInfo.visible = true;
    }
    public showItem() {
        this.Img.source = this.ImgBg.texture;
        this.visible = true;
        this.TxtInfo.visible = false;
    }
    public hideItem() { this.visible = false; }
}